package com.ease.web.xwt.component;

import java.util.ArrayList;
import java.util.List;

import com.ease.web.xwt.vo.XOption;

/**
 * 
 * @author nathanleewei
 * 
 */
public class XSelect extends XAbstractComponent {

	/**
	 *
	 */
	private static final long serialVersionUID = -7302233400593201788L;

	protected boolean disabled;

	protected boolean isMultiple;

	protected int size = 1;

	protected String onChange;

	protected List<XOption> options;

	public XSelect() {
		super();
	}

	public XSelect(String name, String value) {
		super();
		this.setName(name);
		this.setValue(value);
	}

	protected String getTemplate() {
		return TEMPLATE_X_SELECT;
	}

	public void addOption(XOption option) {
		if (null == options) {
			options = new ArrayList<XOption>();
		}

		options.add(option);
	}

	public void addOption(int index, XOption option) {
		if (null == options) {
			options = new ArrayList<XOption>();
		}

		options.add(index, option);
	}

	public void addOnChange(String _onChange) {
		StringBuffer onChangeBuffer = new StringBuffer();

		if (null != this.onChange) {
			onChangeBuffer.append(this.onChange);
		}
		if (null != _onChange) {
			onChangeBuffer.append(_onChange);
		}
		this.onChange = onChangeBuffer.toString();
	}

	/**
	 * @return Returns the disabled.
	 */
	public boolean isDisabled() {
		return disabled;
	}

	/**
	 * @param disabled
	 *            The disabled to set.
	 */
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	/**
	 * @return Returns the isMultiple.
	 */
	public boolean isMultiple() {
		return isMultiple;
	}

	/**
	 * @param isMultiple
	 *            The isMultiple to set.
	 */
	public void setMultiple(boolean isMultiple) {
		this.isMultiple = isMultiple;
	}

	/**
	 * @return Returns the onChange.
	 */
	public String getOnChange() {
		return onChange;
	}

	/**
	 * @param onChange
	 *            The onChange to set.
	 */
	public void setOnChange(String onChange) {
		this.onChange = onChange;
	}

	/**
	 * @return Returns the options.
	 */
	public List<XOption> getOptions() {
		return options;
	}

	/**
	 * @param options
	 *            The options to set.
	 */
	public void setOptions(List<XOption> options) {
		this.options = options;
	}

	/**
	 * @return Returns the size.
	 */
	public int getSize() {
		return size;
	}

	/**
	 * @param size
	 *            The size to set.
	 */
	public void setSize(int size) {
		this.size = size;
	}

}